﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;

public partial class SYS_POPEDOM_Dept_Role_Edit :BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["DeptId"] = Request.QueryString["DeptId"];
            BuildGrid(ViewState["DeptId"].ToString());
        }
    }

    //构建checkboxgroup
    private void BuildGrid(string sDeptId)
    {
        string where = "and creator IN (SELECT su.[USER_ID] FROM SYS_USER su WHERE Charindex(RTRIM('" + BS_LoginDeptId + "'),su.DEPT_ID,0) > 0 ) ";
        DataTable tmpTB = CommonLib.BLL.SYS_DEPT_ROLES.GetListAllRole2(sDeptId,where, "ROLE_ID").Tables[0];
        Store1.DataSource = tmpTB;
        Store1.DataBind();
    }

    //保存部门角色
    [DirectMethod]
    public void SaveDeptRole()
    {
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        foreach (SelectedRow row in sm.SelectedRows)
        {
            CommonLib.Model.SYS_DEPT_ROLES oModel = new CommonLib.Model.SYS_DEPT_ROLES();
            oModel.MASTER_ID = CommonLib.BLL.SYS_DEPT_ROLES.GetNewID();
            oModel.DEPT_ID = ViewState["DeptId"].ToString();
            oModel.ROLE_ID = row.RecordID;
            oModel.CREATOR = BS_LoginUserID;
            try
            {
                CommonLib.BLL.SYS_DEPT_ROLES.Add(oModel);
            }
            catch (Exception ex)
            {
                X.Msg.Alert("系统提示",ex.Message);
            }
        }
    }
}
